import 'package:equatable/equatable.dart';
import 'package:mobile_app.core/core/domain/entities/settings/pronunciation_settings.dart';
import 'package:mobile_app.core/core/domain/entities/tts_voice.dart';
import 'package:mobile_app.core/core/domain/helpers/get_tts_voice/helper.dart';
import 'package:mobile_app.home.menu.settings/pronunciation_settings_page/domain/helpers/normalize_speech_rate/helper.dart';

part 'result.dart';

abstract class Initialize {
  InitializationResult call({
    required PronunciationSettings pronunciationSettings,
  });
}

class InitializeImpl implements Initialize {
  const InitializeImpl({
    required GetTtsVoice getTtsVoice,
    required NormalizeSpeechRate normalizeSpeechRate,
  })  : _getTtsVoice = getTtsVoice,
        _normalizeSpeechRate = normalizeSpeechRate;

  final GetTtsVoice _getTtsVoice;
  final NormalizeSpeechRate _normalizeSpeechRate;

  @override
  InitializationResult call({
    required PronunciationSettings pronunciationSettings,
  }) {
    final currentVoice = _getTtsVoice(
      dialect: pronunciationSettings.dialect,
      amVoiceTitle: pronunciationSettings.amVoiceTitle,
      brVoiceTitle: pronunciationSettings.brVoiceTitle,
    );

    final normalizedSpeechRate = _normalizeSpeechRate(
      speechRate: pronunciationSettings.speechRate,
    );

    final result = InitializationResult(
      voice: currentVoice,
      normalizedSpeechRate: normalizedSpeechRate,
    );

    return result;
  }
}
